package com.hisan.freeride.home.activity;

import android.database.Cursor;
import android.databinding.DataBindingUtil;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Html;
import android.view.Gravity;
import android.view.View;

import com.hisan.freeride.R;
import com.hisan.freeride.common.base.AppConfig;
import com.hisan.freeride.common.base.BaseActivity;
import com.hisan.freeride.common.base.BaseAppLication;
import com.hisan.freeride.common.utils.CacheUtils;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.common.utils.ImageUtils;
import com.hisan.freeride.common.utils.WxShareAndLoginUtils;
import com.hisan.freeride.common.view.RewritePopwindow;
import com.hisan.freeride.databinding.RecommendBinding;

import static com.hisan.freeride.common.utils.WxShareAndLoginUtils.WECHAT_FRIEND;
import static com.hisan.freeride.common.utils.WxShareAndLoginUtils.WECHAT_MOMENT;


/**
 * 创建时间 : 2017/6/8
 * 创建人：yangyingqi
 * 公司：嘉善和盛网络有限公司
 * 备注：推荐页面
 */
public class RecommendActiivity extends BaseActivity<RecommendBinding>{
    private String str="您将获得<font color='#FF9C00'  size:'36px'><small>"+"10积分"+"</small></font>奖励";
    private RewritePopwindow popwindow;
    private String recommend;
    //用户昵称
    private String linkname="";




    @Override
    protected int getLayoutId() {
        return R.layout.recommend;
    }

    @Override
    protected void initView() {
        mBinding.reward.setText(Html.fromHtml(str));
    }

    @Override
    protected void initEvent() {
        mBinding.topBack.setOnClickListener(v -> finishActivity(true));
        mBinding.share.setOnClickListener(v -> {
            popwindow = new RewritePopwindow(RecommendActiivity.this, itemsOnClick);
            popwindow.showAtLocation(v,
                    Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        });
        if (!CollectionUtils.isNullOrEmpty(CacheUtils.getInstance().getString("recommend"))){
            recommend=CacheUtils.getInstance().getString("recommend");
            mBinding.code.setText(recommend);
        }
    }

    @Override
    protected void loadData(boolean isRefresh) {
        if (!CollectionUtils.isNullOrEmpty(CacheUtils.getInstance().getString("nickname"))){
            linkname=CacheUtils.getInstance().getString("nickname");
        }
    }

    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {

        public void onClick(View v) {
            popwindow.dismiss();
            popwindow.backgroundAlpha(RecommendActiivity.this, 1f);
            switch (v.getId()) {

                case R.id.weixinghaoyou:
                    Bitmap bitmap= ImageUtils.getBitmap(getResources(), R.mipmap.sfcar);
                    WxShareAndLoginUtils.WxUrlShare(AppConfig.register,"爱心顺风车",linkname+AppConfig.registername,bitmap ,WECHAT_FRIEND);
                    break;
                case R.id.pengyouquan:
                    Bitmap bitmap2= ImageUtils.getBitmap(getResources(), R.mipmap.sfcar);
                    WxShareAndLoginUtils.WxUrlShare(AppConfig.register,"爱心顺风车",linkname+AppConfig.registername,bitmap2 ,WECHAT_MOMENT);
                    break;
                default:
                    break;
            }
        }
    };
}
